package com.mask.sca.auth.controller;

import com.mask.sca.core.response.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/auth/sms")
public class SmsController {
    @Autowired
    private StringRedisTemplate redisTemplate;

    @PostMapping("/send")
    public ApiResponse<?> sendSms(@RequestParam String phone) {
        if (!phone.matches("^1[3-9]\\d{9}$")) {
            return ApiResponse.success("手机号格式不正确");
        }
        String code = String.valueOf((int)((Math.random()*9+1)*100000));
        redisTemplate.opsForValue().set("sms:code:" + phone, code, 5, TimeUnit.MINUTES);
        // TODO: 调用短信服务发送验证码
        return ApiResponse.success("验证码已发送");
    }
} 